﻿// Decompiled with JetBrains decompiler
// Type: Commom.Util.Json
// Assembly: MT5Trade, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8045A2CB-DBD6-41AD-8804-F98CAC1BDC8D
// Assembly location: C:\projects\trade\trade_tool\trade0812\MT5Trade.dll

using Newtonsoft.Json;

#nullable enable
namespace Commom.Util;

public static class Json
{
  public static T ToObject<T>(string json)
  {
    return string.IsNullOrWhiteSpace(json) ? default (T) : JsonConvert.DeserializeObject<T>(json);
  }

  public static string ToJson(object target, bool isConvertToSingleQuotes = false)
  {
    if (target == null)
      return string.Empty;
    if (target is string)
      return target.ToStr();
    string json = JsonConvert.SerializeObject(target);
    if (isConvertToSingleQuotes)
      json = json.Replace("\"", "'");
    return json;
  }
}
